import Sequelize from 'sequelize';
import baseDao from '../lib/baseDao.js'; // 数据库操作
import Sku from './sku.js'

const Modal = baseDao.sequelize.define('t_item', {
  // 属性
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true, // 主键
    autoIncrement: true, // 自增
    allowNull: true,
    validate: {
      len: [1, 50]
    }
  },
  itemName: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '商品名称'
  },
  itemShelf: {
    type: Sequelize.INTEGER,
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    comment: '上下架状态：0下架，1上架'
  },
  itemMainImg: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 200]
    },
    comment: '商品主图'
  },
  price: {
    type: Sequelize.FLOAT,
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    comment: '列表展示价格'
  },
}, {
    // 参数
  });

Modal.hasMany(Sku.Modal, { foreignKey: 'itemId', targetKey: 'id', as: 'skus' });

//向外暴露
export default {
  Modal,
}